<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="utf-8">
	<title>AmmoPhysics - Three.js Docs</title>
	<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
	<script src="../scripts/highlight.min.js"></script>
	<link type="text/css" rel="stylesheet" href="../styles/highlight-three.css">
	<link type="text/css" rel="stylesheet" href="../styles/page.css">
</head>
<body>
	<h1 translate="no">AmmoPhysics</h1>
		<section>
			<header>
				<div class="class-description"><p>Can be used to include Ammo.js as a Physics engine into
<code>three.js</code> apps. Make sure to include <code>ammo.wasm.js</code> first:</p>
<p>It is then possible to initialize the API via:</p>
<pre><code class="language-js">const physics = await AmmoPhysics();
</code></pre></div>
				<h2>Code Example</h2>
				<div translate="no"><pre class="prettyprint source"><code>&lt;script src=&quot;jsm/libs/ammo.wasm.js&quot;>&lt;/script>
</code></pre></div>
			</header>
			<article>
				<h2 class="subsection-title">Import</h2>
				<p><span translate="no">AmmoPhysics</span> is an addon, and must be imported explicitly, see <a href="https://threejs.org/manual/#en/installation" target="_blank" rel="noopener">Installation#Addons</a>.</p>
				<pre><code class="language-js">import { AmmoPhysics } from 'three/addons/physics/AmmoPhysics.js';</code></pre>
				<div class="container-overview">
					<div class="method">
					</div>
				</div>
				<h2 class="subsection-title">Methods</h2>
					<h3 class="name name-method" id="addMesh" translate="no">.<a href="#addMesh">addMesh</a><span class="signature">( mesh : <span class="param-type"><a href="Mesh.html">Mesh</a></span>, mass : <span class="param-type">number</span>, restitution : <span class="param-type">number</span> )</span> </h3>
					<div class="method">
						<div class="description">
							<p>Adds the given mesh to this physics simulation.</p>
						</div>
						<table class="params">
							<tbody>
								<tr>
									<td class="name">
										<strong>mesh</strong>
									</td>
									<td class="description last">
										<p>The mesh to add.</p>
									</td>
								</tr>
								<tr>
									<td class="name">
										<strong>mass</strong>
									</td>
									<td class="description last">
										<p>The mass in kg of the mesh.</p>
										<p>Default is <code>0</code>.</p>
									</td>
								</tr>
								<tr>
									<td class="name">
										<strong>restitution</strong>
									</td>
									<td class="description last">
										<p>The restitution of the mesh, usually from 0 to 1. Represents how &quot;bouncy&quot; objects are when they collide with each other.</p>
										<p>Default is <code>0</code>.</p>
									</td>
								</tr>
							</tbody>
						</table>
					</div>
					<h3 class="name name-method" id="addScene" translate="no">.<a href="#addScene">addScene</a><span class="signature">( scene : <span class="param-type"><a href="Object3D.html">Object3D</a></span> )</span> </h3>
					<div class="method">
						<div class="description">
							<p>Adds the given scene to this physics simulation. Only meshes with a
<code>physics</code> object in their <a href="Object3D.html#userData">Object3D#userData</a> field will be honored.
The object can be used to store the mass of the mesh. E.g.:</p>
<pre><code class="language-js">box.userData.physics = { mass: 1 };
</code></pre>
						</div>
						<table class="params">
							<tbody>
								<tr>
									<td class="name">
										<strong>scene</strong>
									</td>
									<td class="description last">
										<p>The scene or any type of 3D object to add.</p>
									</td>
								</tr>
							</tbody>
						</table>
					</div>
					<h3 class="name name-method" id="setMeshPosition" translate="no">.<a href="#setMeshPosition">setMeshPosition</a><span class="signature">( mesh : <span class="param-type"><a href="Mesh.html">Mesh</a></span>, position : <span class="param-type"><a href="Vector3.html">Vector3</a></span>, index : <span class="param-type">number</span> )</span> </h3>
					<div class="method">
						<div class="description">
							<p>Set the position of the given mesh which is part of the physics simulation. Calling this
method will reset the current simulated velocity of the mesh.</p>
						</div>
						<table class="params">
							<tbody>
								<tr>
									<td class="name">
										<strong>mesh</strong>
									</td>
									<td class="description last">
										<p>The mesh to update the position for.</p>
									</td>
								</tr>
								<tr>
									<td class="name">
										<strong>position</strong>
									</td>
									<td class="description last">
										<p>The new position.</p>
									</td>
								</tr>
								<tr>
									<td class="name">
										<strong>index</strong>
									</td>
									<td class="description last">
										<p>If the mesh is instanced, the index represents the instanced ID.</p>
										<p>Default is <code>0</code>.</p>
									</td>
								</tr>
							</tbody>
						</table>
					</div>
				<h2 class="subsection-title">Source</h2>
				<p>
					<a href="https://github.com/mrdoob/three.js/blob/master/examples/jsm/physics/AmmoPhysics.js" translate="no" target="_blank" rel="noopener">examples/jsm/physics/AmmoPhysics.js</a>
				</p>
			</article>
		</section>
<script src="../scripts/linenumber.js"></script>
<script src="../scripts/page.js"></script>
</body>
</html>